package com.jwork.progress.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;

@Service
public class RequestAsyncTaskService {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Async
    public void task1(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(1000);
        logger.info("任务1");
        countDownLatch.countDown();
    }

    @Async
    public void task2(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(1000);
        logger.info("任务2");
        countDownLatch.countDown();
    }

    @Async
    public void task3(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(600);
        logger.info("任务3");
        countDownLatch.countDown();
    }

    @Async
    public void task4(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(300);
        logger.info("任务4");
        countDownLatch.countDown();
    }

    @Async
    public void task5(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(1000);
        logger.info("任务5");
        countDownLatch.countDown();
    }

    @Async
    public void task6(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(100);
        logger.info("任务6");
        countDownLatch.countDown();
    }

    @Async
    public void task7(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(200);
        logger.info("任务7");
        countDownLatch.countDown();
    }
}
